package com.dao.zk;

import com.bean.zk.State;
import com.util.zk.Dbutil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

@Repository
public class StateDAO {

    /**
     * 查询所有状态
     * @return
     */
    public List<State> getStates() {
        Connection con = null;
        QueryRunner query = new QueryRunner();
        List<State> states = new ArrayList<>();
        try {
            con = Dbutil.getConnection();
            String sql = "select * from state;";
            states = query.query(con, sql, new BeanListHandler<>(State.class));
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            Dbutil.closeAll(null,null,con);
        }
        return states;
    }
}
